package cn.example.vip.mall.goods.controller;

import cn.example.vip.mall.goods.entity.Product;
import cn.example.vip.mall.goods.service.SpuService;
import cn.example.vip.mall.util.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin    // 生产环境需要去掉
@RestController
@RequestMapping("/spu")
public class SpuController {
	@Autowired
	private SpuService spuService;
	
	/**
	 * 产品保存
	 */
	@PostMapping("/save")
	public RespResult save(Product product) {
		spuService.saveProduct(product);
		return RespResult.ok();
	}
	
	/**
	 * 根据spuId查询Product
	 */
	@GetMapping("/product/{id}")
	public RespResult<Product> findProductById(@PathVariable("id") String id) {
		return RespResult.ok(spuService.findProductBySpuId(id));
	}
	
}
